/*
 * platfrom_type.c
 *
 *  Created on: 2024-4-15
 *      Author: NI
 */

#include <stdint.h>
#include <sys/mman.h>
#include <stdio.h>
#include <arm/inout.h>
#include "mx6x.h"
#include "platfrom_type.h"

enum mx6_chip_type_list {
	MX6_CHIP_TYPE_QUAD_OR_DUAL 	= 0x63,
	MX6_CHIP_TYPE_DUAL_LITE_OR_SOLO = 0x61,
};

int get_cpu_type(void){
	uintptr_t anatop_vbase = mmap_device_io(MX6X_ANATOP_SIZE, MX6X_ANATOP_BASE);
	if (anatop_vbase == (uintptr_t) MAP_FAILED ) {
		fprintf(stderr, "%s: ANATOP_BASE mmap_device_io[0x%X] error!\n", __FUNCTION__,MX6X_ANATOP_BASE);
		return (-1);
	}
	uint32_t chip_id = in32(anatop_vbase + MX6X_ANADIG_CHIP_INFO);
	if(-1 == munmap_device_io(anatop_vbase, MX6X_ANATOP_SIZE)){
		fprintf(stderr, "%s: ANATOP_BASE unmap[0x%X] failed!\n", __FUNCTION__, MX6X_ANATOP_BASE);
		return(-1);
	}
	chip_id >>= 16;
	if(chip_id == MX6_CHIP_TYPE_QUAD_OR_DUAL){
		return (IMX6DQ);
	}
	else if(chip_id == MX6_CHIP_TYPE_DUAL_LITE_OR_SOLO){
		return (IMX6SDL);
	}
	return (-1);
}


